package com.ruoyi.pcj.controller;

import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.annotation.Log;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pcj.domain.PcjTbSubject;
import com.ruoyi.pcj.service.IPcjTbSubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子话题Controller
 * 
 * @author ms
 * @date 2024-03-09
 */
@RestController
@RequestMapping("/pcj/subject")
public class PcjTbSubjectController extends BaseController
{
    @Autowired
    private IPcjTbSubjectService pcjTbSubjectService;

    /**
     * 分页查询帖子话题列表
     * @param params 最基本参数{"pageNum":1,"pageSize":10}，其他参数自行定义
     */
    @PreAuthorize("@ss.hasPermi('pcj:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params)
    {
        IPage<PcjTbSubject> page = pcjTbSubjectService.selectPcjTbSubjectList(params);
        return getDataTableMp(page);
    }



    /**
     * 导出帖子话题列表
     */
    @PreAuthorize("@ss.hasPermi('pcj:subject:export')")
    @Log(title = "帖子话题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> params)
    {
        IPage<PcjTbSubject> page = pcjTbSubjectService.selectPcjTbSubjectList(params);
        ExcelUtil<PcjTbSubject> util = new ExcelUtil<PcjTbSubject>(PcjTbSubject.class);
        util.exportExcel(response, page.getRecords(), "帖子话题数据");
    }

    /**
     * 获取帖子话题详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcj:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(pcjTbSubjectService.selectPcjTbSubjectById(id));
    }

    /**
     * 新增帖子话题
     */
    @PreAuthorize("@ss.hasPermi('pcj:subject:add')")
    @Log(title = "帖子话题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcjTbSubject pcjTbSubject)
    {
        return toAjax(pcjTbSubjectService.insertPcjTbSubject(pcjTbSubject));
    }

    /**
     * 修改帖子话题
     */
    @PreAuthorize("@ss.hasPermi('pcj:subject:edit')")
    @Log(title = "帖子话题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcjTbSubject pcjTbSubject)
    {
        return toAjax(pcjTbSubjectService.updatePcjTbSubject(pcjTbSubject));
    }

    /**
     * 删除帖子话题
     */
    @PreAuthorize("@ss.hasPermi('pcj:subject:remove')")
    @Log(title = "帖子话题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(pcjTbSubjectService.deletePcjTbSubjectByIds(ids));
    }
}
